<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>19上传</title>
  <script type="text/javascript" src="../layui-v2.7.6/layui/layui.js"></script>
  <script type="text/javascript" src="../layui-v2.7.6/layui/jquery-1.10.1.js"></script>
  <link rel="stylesheet" href="../layui-v2.7.6/layui/css/layui.css">
</head>
<body>
<button type="button" class="layui-btn" id="test1">
  <i class="layui-icon">&#xe67c;</i>上传图片
</button>

<script>
  layui.use('upload', function(){
    var upload = layui.upload;

    //执行实例
    var uploadInst = upload.render({
      elem: '#test1' //绑定元素
      ,url: '/upload/' //上传接口
      ,accept: 'images' //只允许上传图片
      ,size: 1024 * 5
        ,acceptMime: 'image/*' //只筛选图片
      ,done: function(res){
        //上传完毕回调
      }
      ,error: function(){
        //请求异常回调
        alert("出错了")
      }
    });
  });
</script>
</body>
</html>